//
//  QDLargeTitleViewController.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/2/25.
//  Copyright © 2019 YueWen. All rights reserved.
//

import UIKit

/// 集成 QDLargeTitleTableHeaderView 滚动的控制器
class QDLargeTitleViewController: NWTableViewController,QDLargeTitleTableHeaderScrollable {
    
    /// 所有的正标题
    var titles: [String] {
        get { return[] }
    }
    
    /// 所有的副标题
    var subtitles: [String]{
        get { return [String](repeating: "", count: titles.count) }
    }
    
    
    /// tableView的标题headerView
    let largeTableHeaderView = QDLargeTitleTableHeaderView()
    
    
    override func loadPropertysAtInitialization() {
        super.loadPropertysAtInitialization()
        headerRefreshEnable = false
        footerRefreshEnable = false
        tableView.rowHeight = 62.5
    }
    
    
    
    override func registerTableViewCellsAndReusableView() {
        tableView.register(QDTitleTableViewCell.self, forCellReuseIdentifier: "cell")
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        largeTableHeaderView.frame = CGRect(origin: .zero, size: CGSize(width: ritl_width, height: QDLargeTitleTableHeaderViewNormalHeight))
        tableView.tableHeaderView = largeTableHeaderView
    }
    
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        setNavigationBarShadowViewHidden(navigationItem.title == nil)
    }
    
    
    
    // MARK: NavigationBar
    override var nav_mutableBarShadowHidden: Bool { return true }
    
    
    // MARK: UIScrollView
    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        tableViewDidScroll(contentOfset: scrollView.contentOffset){ isShow in
            setNavigationBarShadowViewHidden(!isShow)
        }
    }
    
    
    // MARK: UITableViewDataSource
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titles.count
    }
    
    
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        
        if cell is QDTitleTableViewCell, let settingCell = cell as? QDTitleTableViewCell {
            settingCell.titleLabel.text = titles[indexPath.row]
            settingCell.subtitleLabel.text = subtitles[indexPath.row]
        }
        
        return cell
    }
}
